package com.hewanglan.subject.application.controller;

import com.alibaba.fastjson.JSON;
import com.hewanglan.subject.common.entity.Result;
import com.hewanglan.subject.infra.entity.UserInfo;
import com.hewanglan.subject.infra.rpc.UserRPC;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/test")
public class testController {
    @Resource
    private UserRPC userRPC;

    @Resource
    private RocketMQTemplate rocketMQTemplate;
    @RequestMapping("/getUserInfo")
    public String getUserInfo(){
        UserInfo userInfo = userRPC.getUserInfo("owF9J6qmz0ROH-Hng31iSQBGtFfk");
        String res= JSON.toJSONString(userInfo);
        return res;
    }

    @RequestMapping("/pushMessage")
    public Result<Boolean> pushMessage(@RequestParam("id") Integer id){
        rocketMQTemplate.convertAndSend("first-payload","测试发送消息"+id);
        return Result.ok(Boolean.TRUE);
    }
}

